#include "buttonfunctionmap.h"
#include "instructionEnum.h"
#include <QDebug>

ButtonFunctionMap::ButtonFunctionMap(QMap<int, int> usualButtonFunctionIn, QObject *parent):
                                            QObject(parent)
{
        usualButtonFunction=usualButtonFunctionIn;
}

QString ButtonFunctionMap::getFunctionTextByButtonId(int buttonId)
{
    QString tmpStr;
    if(false==usualButtonFunction.contains(buttonId))
    {
        return tmpStr;
    }
    int commandId=usualButtonFunction.value(buttonId);
    switch(commandId)
    {
    case EB_MOVE_J:
    {
        tmpStr= "关节";
        break;
    }
    case EB_MOVE_L:
    {
        tmpStr= "直线";
        break;
    }
    case EB_MOVE_C:
    {
        tmpStr= "圆弧";
        break;
    }
    case EB_LABEL:
    {
        tmpStr= "标签";
        break;
    }
    case EB_JUMP:
    {
        tmpStr= "跳转";
        break;
    }
    case EB_CONDITION:
    {
        tmpStr= "条件";
        break;
    }
    case EB_WAIT:
    {
        tmpStr= "等待";
        break;
    }
    case EB_DO:
    {
        tmpStr= "端口";
        break;
    }
    case EB_AO:
    {
        tmpStr= "模拟";
        break;
    }
    case EB_MOVEMAG:
    {
        tmpStr= "磁导航";
        break;
    }
    case EB_MOVEFREE:
    {
        tmpStr= "自由导航";
        break;
    }
    case EB_SET_ODOM:
    {
        tmpStr= "里程计";
        break;
    }
    case EB_CHECK_BATTERY:
    {
        tmpStr= "电量";
        break;
    }
    case EB_WAIT_EXT_COMMAND:
    {
        tmpStr= "等命令";
        break;
    }
    case EB_ROBOT_MOVE:
    {
        tmpStr= "机械手控制";
        break;
    }
    case EB_ROLLER:
    {
        tmpStr= "滚筒";
        break;
    }
    case EB_MUSIC:
    {
        tmpStr= "音乐";
        break;
    }
    case EB_LOAD_MAP:
    {
        tmpStr= "加载地图";
        break;
    }
    case EB_CHARGE:
    {
        tmpStr= "充电";
        break;
    }
    case EB_LIFT:
    {
        tmpStr= "升降机构";
        break;
    }
    case EB_AXIS_MOVE:
    {
        tmpStr= "单轴运动";
        break;
    }
    case EB_R_REGISTER:
    {
        tmpStr= "R寄存器";
        break;
    }
    case EB_PR_REGISTER:
    {
        tmpStr= "PR寄存器";
        break;
    }
    case EB_PL_REGISTER:
    {
        tmpStr= "PL寄存器";
        break;
    }
    case EB_TIMER_REGISTER:
    {
        tmpStr= "时间寄存器";
        break;
    }

    }
    return tmpStr;
}

int ButtonFunctionMap::emitSignalByButtonId(int buttonId)
{

    if(false==usualButtonFunction.contains(buttonId))
    {
        qDebug()<<"error,false==usualButtonFunction.contains(buttonId) "<<buttonId;
        return -1;
    }
    int commandId=usualButtonFunction.value(buttonId);
    switch(commandId)
    {
    case EB_MOVE_J:
    {
        emit jInstruction();
        break;
    }
    case EB_MOVE_L:
    {
        emit lInstruction();
        break;
    }
    case EB_MOVE_C:
    {
        emit arcInstruction();
        break;
    }
    case EB_LABEL:
    {
        emit labelInstruction();
        break;
    }
    case EB_JUMP:
    {
        emit jumpInstruction();
        break;
    }
    case EB_CONDITION:
    {
        emit conditionInstruction();
        break;
    }
    case EB_WAIT:
    {
        emit waitInstruction();
        break;
    }
    case EB_DO:
    {
        emit numberInstruction();
        break;
    }
    case EB_AO:
    {
        emit analogInstruction();
        break;
    }
    case EB_MOVEMAG:
    {
        emit moveMagInstruction();
        break;
    }
    case EB_MOVEFREE:
    {
        emit moveFreeInstruction();
        break;
    }
    case EB_SET_ODOM:
    {
        emit setOdometryInstruction();
        break;
    }
    case EB_CHECK_BATTERY:
    {
        emit addCheckBatteryInstruction_signal();
        break;
    }
    case EB_WAIT_EXT_COMMAND:
    {
        emit addWaitCommandInstruction_signal();
        break;
    }
    case EB_ROBOT_MOVE:
    {
        emit addRobotMoveInstruction_Signal();
        break;
    }
    case EB_ROLLER:
    {
        emit addRollerInstruction_Signal();
        break;
    }
    case EB_MUSIC:
    {
        emit musicInstruction();
        break;
    }
    case EB_LOAD_MAP:
    {
        emit addLoadMapInstruction_signal();
        break;
    }
    case EB_CHARGE:
    {
        emit chargingInstruction();
        break;
    }
    case EB_LIFT:
    {
        emit liftMechanismInstruction();
        break;
    }
    case EB_AXIS_MOVE:
    {
        emit axisMoveInstruction_signal();
        break;
    }
    case EB_R_REGISTER:
    {
        emit rInstruction();
        break;
    }
    case EB_PR_REGISTER:
    {
        emit pRInstruction();
        break;
    }
    case EB_PL_REGISTER:
    {
        emit pLInstruction();
        break;
    }
    case EB_TIMER_REGISTER:
    {
        emit timerInstruction();
        break;
    }
    }
    return 1;
}
